﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class add_group : Form
    {
        SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\elkolyaa\calendar-maintainer-508c42534a4c\calendar-maintainer-508c42534a4c\WindowsFormsApplication1\WindowsFormsApplication1\usersDB.mdf;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();

        private class Item
        {
            public string Name;
            public int Value;
            public Item(string name, int value)
            {
                Name = name; Value = value;
            }
            public override string ToString()
            {
                // Generates the text shown in the combo box
                return Name;
            }
        }
        static int i = 1;
        public add_group()
        {
            InitializeComponent();
            for (int x = 2; x <= 25; x++)
            {
                combfrom.Items.Add(x - 1);
                combto.Items.Add(x - 1);
            }

        }

        public string mail12, mail2, mail3, mail4;


        public void button1_Click(object sender, EventArgs e)
        {
            object from = combfrom.SelectedItem;
            int from1 = Convert.ToInt32(from);
            object to = combto.SelectedItem;
            int to1 = Convert.ToInt32(to);
            string descrip = eventdesc.Text;
            string dayy = label6.Text;
            string numday = label5.Text;
            int nd = int.Parse(label5.Text);
            string Month = label7.Text;
            int m = int.Parse(label7.Text);
            string yearr = label8.Text;
            int y = int.Parse(label8.Text);
            string emaill = email.Text;


            add_group group = new add_group();
            for (int x = 0; x < mytextboxes.Count; x++)
            {
                if (x == 0)
                {
                    mail12 = mytextboxes[x].Text.ToString();
                }
                else if (x == 1)
                {
                    mail2 = mytextboxes[x].Text.ToString();
                }
                else if (x == 2)
                {
                    mail3 = mytextboxes[x].Text.ToString();
                }
                else if (x == 3)
                {
                    mail4 = mytextboxes[x].Text.ToString();
                }
            }

            group_class MyObject2 = new group_class();
            MyObject2.Add_group(emaill, descrip, from1, to1, label6.Text, nd, m, y, mail12, mail2, mail3, mail4);

            string day = label5.Text, day_name = label6.Text, month = label7.Text, year = label8.Text;

        }
        public static List<TextBox> mytextboxes = new List<TextBox>();
        public void buttonclick_Click(object sender, EventArgs e)
        {
            int counter = 1;
            if (i <= 4)
            {
                TextBox tb = new TextBox();
                tb.Name = "txtemail" + counter;
                Point p = new Point(80, 185 + (25 * i));
                tb.Location = p;
                tb.Size = new System.Drawing.Size(230, 35);
                tb.ForeColor = System.Drawing.Color.Purple;
                tb.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.Controls.Add(tb);
                mytextboxes.Add(tb);
                i++;
                counter++;

            }
            else
            {
                MessageBox.Show("you can't add more than 4", "TextBox");
            }

        }
        private void add_group_Load(object sender, EventArgs e)
        {
            cmd.Connection = cn;
        }

    }
}
